package com.example.spring.demo.mapper;

import com.example.spring.demo.entity.Message;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author qwert
 * @version 1.0.0
 * @create 2024/12/29 10:42
 **/
@Mapper
public interface MessageMapper {

    @Select("""
select * from message where id = #{id}
""")
    Message getMessageById(String id);

    @Select("""
select * from message where name like #{name}

""")
    Message getMessageByName(String name);

    @Insert("""
insert into message (id, name, content, create_time, update_time) 
values (#{id}, #{name}, #{content}, now(), now());
""")
    int saveMessage(Message message);

    @Select("""
<script>
select * from message
where id in
<foreach item='id' index='index' collection='messageList' open='(' separator=',' close=')'> #{id} </foreach>
</script>
"""
    )
    List<Message> getMessageList(List<String> messageList);
}
